<extend name="Base/common" />

<block name="style">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Api/css/order.css">
</block>

<block name="Content">

<div class="page-group">
    <div class="page page-current">
        <form action="{:U('UserAddress/saveAction')}" method="post" class="personal-info address-add my-order">
            <div class="order-foot bar bar-standard bar-footer">
                <div class="content-block order-foot-block">
                    <div class="row">
                        <div class="col-100">
                        	<a href="#" class="button button-big button-fill button-pay" onclick="add()">确认</a>
                        </div>
                        <input type="hidden" name="type" id="type" value="{$type}"/>
                    	<input type="hidden" name="data" id="data" value="{$data}"/>
                    	<input type="hidden" name="address_id" id="address_id" value="{$addressModel['address_id']}"/>
                    	<input type="hidden" name="latitude" id="latitude" value="{$addressModel['latitude']|default=''}"/>
                    	<input type="hidden" name="longitude" id="longitude" value="{$addressModel['longitude']|default=''}"/>
                    	<input type="hidden" name="city" id="city" value="{$addressModel['city']|default=''}"/>
                    	<input type="hidden" name="address" id="address" value="{$addressModel['address']|default=''}"/>
                    </div>
                </div>
            </div>
            <div class="content ">
                <!--个人资料主体内容-->
                <ul class="address">
                    <li>
                        <span class="left">地址</span><span class="address-get">{$addressModel['address']|default='请使用地图定位您的维修地址'}</span><a href="#" class="icon-map" onclick="mapapi();"></a>
                    </li>
                    <li style="position:relative;">
                    	<span class="address-details">
                    		<input type="text" placeholder="详细地址" name="name" id="name" value="{$addressModel['name']|default=''}"/>
                    	</span>
                    	<a href="#" class="delete right" style="right:0.75rem"></a>
                    </li>
                </ul>
                <div class="list-block">
                    <ul>
                        <li class="contacts">
                            <a href="#" class="item-link item-content">
                                <div class="item-inner">
                                    <div class="item-title label">联系人</div>
                                    <div class="item-input">
                                        <input class="right" type="text" name="contact" id="contact"
                                        	value="{$addressModel['contact']|default=''}" 
                                        	placeholder="您的姓名" style="text-align: right;">
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="gender">
                            <a href="#" class="item-link item-content">
                                <div class="item-inner">
                                    <div class="item-title label">性别</div>
                                    <div class="item-input">
                                        <input type="text" placeholder="男" id="picker" name="picker" 
                                        	value="<if condition='$addressModel.sex eq 1'>男<else/>女</if>" readonly>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class="contact-tel">
                            <a href="#" class="item-link item-content">
                                <div class="item-inner">
                                    <div class="item-title label">联系电话</div>
                                    <div class="item-input">
                                        <input class="right" type="text" name="telphone" id="telphone" 
                                        	value="{$addressModel['telphone']}" placeholder="联系电话" style="text-align: right;">
                                    </div>
                                    <!--<div class="right phone-num"></div>-->
                                </div>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </form>
    </div>
</div>

</block>

<block name="script">
<script src="__PUBLIC__/Api/js/order.js" type="text/javascript"></script>
<script type="text/javascript">

function mapapi(){
	
	var type = $("#type").val();
	var addressID = $("#address_id").val();
	var callback = 'http://' + window.location.host
				+ Think.U('UserAddress/editAction', '&type='+type+'&address_id='+addressID);

	window.location.href = 'http://apis.map.qq.com/tools/locpicker?search=1&type=0&backurl=' + callback 
							+ '&key=WQJBZ-F5OKV-4HPPF-UHKNQ-7WSGV-QCBB3&referer=myapp';
}

function add(){
	
	var latitude = $("#latitude").val();
	var longitude = $("#longitude").val();
	var contact = $("#contact").val();
	var telphone = $("#telphone").val();
	var name = $("#name").val();
	
	if(!latitude || !longitude){
		$.alert('请选择地址');
		return false;
	}else if(!contact){
		$.alert('请填写联系人姓名');
		return false;
	}else if(!(/^1((3|4|5|8){1}\d{1}|70)\d{8}$/.test(telphone))){
		$.alert("手机号码格式有误，请确认");  
		return false;
	}else if(!name){
		$.alert("请填写详细地址");  
		return false;
	}else{
		$(document).find('form').submit();
	}
}

</script>
</block>

